package niit.game;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Bullet {
	int x;
	int y;
	int xSpeed;
	int ySpeed;
	GameView gameView;
	MyPlane myPlane;
	Bitmap typeBullet;
	int direct;
	int damge;

	public Bullet(GameView gameView, Bitmap bmp, int x, int y, int xSpeed,
			int ySpeed, int damge, int direct) {

		this.gameView = gameView;
		this.typeBullet = bmp;
		this.x = x;
		this.y = y;
		this.ySpeed = ySpeed;
		this.xSpeed = xSpeed;
		this.direct = direct;
		this.damge = damge;
	}

	private void update() {
		y -= ySpeed;

	}

	private void update1() {
		y += 3 * ySpeed + 2;
		fire_enemy();

	}

	private void update2() {
		x -= xSpeed;
		y = 3 * x;
	}

	private void update3() {
		x += xSpeed;
		y = 1200 - 3 * x;
	}

	public boolean isCollision(int x, int y, Bitmap bmp) {
		return Math.sqrt(Math.pow(this.x - x + this.typeBullet.getWidth() / 2
				- bmp.getWidth() / 2, 2)
				+ Math.pow(
						this.y - y + this.typeBullet.getHeight() / 2
								- bmp.getHeight() / 2, 2)) < this.typeBullet
				.getHeight() / 2 + bmp.getHeight() / 2 - 10;
	}

	public void fire_enemy() {
		if (gameView.enemy != null) {
			for (int i = 0; i < gameView.enemy.size(); i++) {
				if (isCollision(gameView.enemy.get(i).x,
						gameView.enemy.get(i).y, gameView.enemy.get(i).enemyBit)) {
					MyPlane.CurrentScore += 10;
					gameView.enemy.remove(i);
					myPlane.bullets.remove(this);
				}
			}
		}
	}

	public void onDraw(Canvas canvas) {
		update();
		canvas.drawBitmap(typeBullet, x, y, null);
	}

	public void onDraw1(Canvas canvas) {
		update1();

		canvas.drawBitmap(typeBullet, x, y, null);
	}

	public void onDraw2(Canvas canvas) {
		update2();
		canvas.drawBitmap(typeBullet, x, y, null);
	}

	public void onDraw3(Canvas canvas) {
		update3();
		canvas.drawBitmap(typeBullet, x, y, null);
	}

	public int getDirect() {
		return direct;
	}
}
